<template>
	<view>
		<!-- 群公告 -->
	<!-- 	<view class="text_26 icon_ group_notice" v-if="item.type === 'group_notice'">
			管理员设置了新的
			<text style="color: #fe6702; margin: 0 10rpx">群公告</text>
			请及时查看
		</view>
		<view class="text_26 icon_ group_notice" v-else-if="item.type === 'update_group_name'">
			管理员修改了群名称为:"
			<text style="color: #fe6702; margin: 0 10rpx">{{ item.payload.name }}</text>
			"
		</view> -->
		<view class="flex_r item" :class="{ item_: isMy }">
			<view class="item-img" @longpress.stop="longpressAvatar" @click.stop="onItem">
				<!-- <view class="item-img-pendant">
					<image class="img" :src="item.senderData.avatar_pendant" mode="aspectFill"></image>
				</view> -->
				<view class="z_index2 item-img-url">
					<image class="img" :src="item.sender_headimgurl" mode="aspectFill"></image>
				</view>
			</view>
			<view style="width: 22rpx"></view>
			<view class="item-content" :class="{ item_content: !isMy, item_content2: !item.sender_name }">
				<view class="text_24 color__ item-name" v-if="item.sender_name">{{ item.sender_name }}</view>
				<view class="flex_r fa_c item-content-box" :class="{ row_reverse: isMy }">
					<view class="flex_r fa_c item-content-box-box" :class="'A' + item.timestamp" @longpress.stop="longpress">
						<view v-if="isMy">
							<view class="loading" v-if="item.status === 'new' || item.status === 'sending'">
								<m-loading-icon iconColor="#989898"></m-loading-icon>
							</view>
							<view class="loading" v-if="item.status === 'error'">
								<image
									class="img"
									src=""
									mode="aspectFill"
								></image>
							</view>
						</view>
						<view v-if="item.type==1">
							<m-text :isMy="isMy" :value="item" @onClick="onClick"></m-text>
						</view>
						<view v-else-if="item.type==2" @tap.stop="onClick">
							<m-image :isMy="isMy" :value="item"></m-image>
						</view>
						<!-- <view v-else-if="item.type === 'video'" @tap.stop="onClick">
							<m-video :isMy="isMy" :value="item"></m-video>
						</view>
						<view v-else-if="item.type === 'audio'">
							<m-audio :isMy="isMy" :value="item" @onClick="onClick"></m-audio>
						</view> -->
						<!-- 红包 -->
						<!-- <view v-else-if="item.type === 'red_envelope'">
							<m-red-packet :isMy="isMy" :myid="myid" :value="item" @onClick="onClick"></m-red-packet>
						</view> -->
						<!-- 表情包 -->
						<view v-else-if="item.type === 1" @tap.stop="onClick">
							<m-emoji-img :isMy="isMy" :value="item"></m-emoji-img>
						</view>
						<!-- 位置 -->
						<!-- <view v-else-if="item.type === 'map'">
							<m-map :isMy="isMy" :value="item" @onClick="onClick"></m-map>
						</view> -->
						<!-- 文章 -->
						<!-- <view v-else-if="item.type === 'article'">
							<m-article :isMy="isMy" :value="item" @onClick="onClick"></m-article>
						</view> -->
						<!-- 商家分享 -->
						<!-- <view v-else-if="item.type === 'share_SBCF'">
							<m-share-sbcf :isMy="isMy" :value="item" @onClick="onClick"></m-share-sbcf>
						</view>
						<view v-else-if="item.type === 'share_mall'">
							<m-share-mall :isMy="isMy" :value="item" @onClick="onClick"></m-share-mall>
						</view> -->
					<!-- 	<view v-else-if="item.type === 'functional_module'">
							<m-functional-module :isMy="isMy" :value="item" @onClick="onClick"></m-functional-module>
						</view> -->

						<view class="flex1"></view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { to, vibrateShort } from '@/utils/chat.js';
import mText from './m-text.vue';
import mImage from './m-image.vue';
import mVideo from './m-video.vue';
import mAudio from './m-audio.vue';
import mRedPacket from './m-redPacket.vue';
import mMap from './m-map.vue';
import mEmojiImg from './m-emoji-img.vue';
import mArticle from './m-article.vue';
import mShareSbcf from './m-share-sbcf.vue';
import mShareMall from './m-share-mall.vue';

import mFunctionalModule from './m-functional-module.vue';

let isLongpress = false;
let isLongpressAvatar = false;
export default {
	components: {
		mText,
		mImage,
		mVideo,
		mAudio,
		mRedPacket,
		mMap,
		mEmojiImg,
		mArticle,
		mShareSbcf,
		mShareMall,
		mFunctionalModule
	},
	props: {
		myid: {
			type: [String, Number],
			default: null
		},
		isMy: {
			type: [Boolean, Number],
			default: false
		},
		item: {
			type: Object,
			default: {}
		},
		index: {
			type: Number,
			default: 0
		}
	},
	data() {
		return {
			userInforData: {}
		};
	},
	created() {},
	methods: {
		onClick() {
			if (isLongpress) return (isLongpress = false);
			if (this.item.status === 'error') return;
			this.$emit('onClick', this.item, this.index);
		},
		// @某人
		longpressAvatar() {
			isLongpressAvatar = true;
			this.$emit('mention', this.item, this.index);
		},
		onItem() {
			if (isLongpressAvatar) return (isLongpressAvatar = false);
			console.log(this.item);
			to('/pagesGoEasy/group_member_infor/index', { member_id: this.item.senderId, group_id: this.item.groupId });
		},

		// 长按
		longpress(e) {
			isLongpress = true;
			vibrateShort();
			console.log(this.item);
			this.$nextTick(() => {

				const query = uni.createSelectorQuery().in(this);
				query.select(`.A${this.item.timestamp}`)
					.boundingClientRect((data) => {
						this.$emit('onLongpress', this.item, data);
					})
					.exec();
			});
		}
	}
};
</script>

<style scoped lang="scss">
.group_notice {
	width: 100%;
	height: 80rpx;
	color: #a3a3a3;
}
.row_reverse {
	flex-direction: row-reverse;
}
.item {
	position: relative;
	z-index: 0;
	width: calc(100% - 50rpx);
	margin: 0 auto;
	margin-bottom: 28rpx;
	.item-name {
		margin-bottom: 4rpx;
	}
}
.item_ {
	flex-direction: row-reverse;
	.item-name {
		position: relative;
		top: 0rpx;
		display: none;
	}
}
.item-img {
	position: relative;
	width: 76rpx;
	height: 76rpx;
	.item-img-pendant {
		position: absolute;
		z-index: 3;
		top: -2rpx;
		left: -2rpx;
		right: -2rpx;
		bottom: -2rpx;
	}
	.item-img-url {
		width: 76rpx;
		height: 76rpx;
		overflow: hidden;
		border-radius: 6rpx;
		background-color: #fff;
	}
}
.item-content {
	width: calc(100% - 164rpx);
	.item-content-box {
		position: relative;
		.item-content-box-box {
		}
		.loading {
			width: 40rpx;
			height: 40rpx;
			margin: 0 10rpx;
		}
	}
}
.item_content {
	position: relative;
	top: -10rpx;
}
.item_content2 {
	position: relative;
	top: 0rpx !important;
}
</style>
